home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume15 / newgetty < prev    next >
Encoding:
Internet Message Format  |  1988-06-01  |  7.3 KB

  1. Subject:  v15i026:  Alternate getty front-end, with speed detection
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: michael@stb.UUCP (Michael Gersten)
  7. Posting-number: Volume 15, Issue 26
  8. Archive-name: newgetty
  9.  
  10. [  This plays around with the inside of the FILE structure.
  11.    I wrote the Makefile and edited Michael's manual page.  -r$  ]
  12.  
  13. This is an alternative front end to getty. It does not replace getty;
  14. it will call getty if needed (assumed to be placed in /etc/lib/getty).
  15.  
  16. It does have the following features:
  17. 1. Automatic recognition of 300/1200/2400/9600 baud
  18. 2. The ability to run any program or shell script, not just /etc/login.
  19. 3. Variable prompting.
  20.  
  21. Here I have a public access BBS on the same line. Most of my users wouldn't
  22. know what to do if told "Login:" (even though bbs, help, and "?" all work).
  23.  
  24. If an upper case letter is given, this program sets the LCASE bit before
  25. going to the next program.
  26.  
  27. : Michael Gersten
  28. :                 ihnp4!hermix!ucla-an!denwa!stb!michael
  29. :                sdcsvax!crash!gryphon!denwa!stb!michael
  30. : "A hacker lives forever, but not so his free time"
  31.  
  32. #! /bin/sh
  33. # This is a shell archive.  Remove anything before this line, then unpack
  34. # it by saving it into a file and typing "sh file".  To overwrite existing
  35. # files, type "sh file -c".  You can also feed this as standard input via
  36. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  37. # will see the following message at the end:
  38. #        "End of shell archive."
  39. # Contents:  Makefile newgetty.man newgetty.c
  40. # Wrapped by rsalz@fig.bbn.com on Thu Jun  2 14:59:18 1988
  41. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  42. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  43.   echo shar: Will not clobber existing file \"'Makefile'\"
  44. else
  45. echo shar: Extracting \"'Makefile'\" \(240 characters\)
  46. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  47. X##
  48. X##
  49. X
  50. X# Apparently this is needed for Xenix:
  51. X#LIBS=-lx
  52. CFLAGS=-O
  53. X
  54. all:        newgetty newgetty.man
  55. install:    all
  56. X    @echo Install according to local convention
  57. X
  58. newgetty:    newgetty.c
  59. X    @rm -f newgetty
  60. X    $(CC) -o newgetty $(CFLAGS) newgetty.c $(LIBS)
  61. END_OF_FILE
  62. if test 240 -ne `wc -c <'Makefile'`; then
  63.     echo shar: \"'Makefile'\" unpacked with wrong size!
  64. fi
  65. # end of 'Makefile'
  66. fi
  67. if test -f 'newgetty.man' -a "${1}" != "-c" ; then 
  68.   echo shar: Will not clobber existing file \"'newgetty.man'\"
  69. else
  70. echo shar: Extracting \"'newgetty.man'\" \(1700 characters\)
  71. sed "s/^X//" >'newgetty.man' <<'END_OF_FILE'
  72. X.TH NEWGETTY 8 
  73. X.SH NAME
  74. newgetty \- baud rate detecting version of getty (and more)
  75. X.SH SYNTAX
  76. X.B "getty b"
  77. X.br
  78. X.B "getty <anything else>"
  79. X.SH DESCRIPTION
  80. X.I newgetty
  81. is a front end to
  82. X.IR /etc/getty .
  83. It assumes that the old system supplied getty is in
  84. X.IR /etc/lib/getty ; if the argument is anything other than
  85. X.B b
  86. it calls that program with the argument.
  87. X.PP
  88. If the argument is
  89. X.BR b ,
  90. it trys to open
  91. X.IR /etc/default/getty ,
  92. which must contain a line like:
  93. X.RS
  94. prompt=Any string that you want to output
  95. X.RE
  96. X.PP
  97. XFor example,
  98. X.RS
  99. prompt=<b>bs or <u>nix
  100. X.RE
  101. It will then wait for a character (with a timeout, currently of 3 seconds),
  102. at which point it will change baud rates (currently 9600/2400/1200/300),
  103. and try again.
  104. X.PP
  105. XEventually it will get a character, which it will then try to find a
  106. line for in
  107. X.IR /etc/default/getty .
  108. This line should contain the name of the program or shell script to execute.
  109. As an example:
  110. X.RS
  111. X.nf
  112. prompt=<b>bs or <u>nix
  113. b=/bbs/login
  114. B=/bbs/login
  115. u=/etc/login
  116. U=/etc/login
  117. x=/etc/login
  118. XX=/etc/login
  119. X.fi
  120. X.RE
  121. X.PP
  122. X.I Newgetty
  123. is smart enough to set the uppercase flag if an uppercase letter comes in;
  124. other than that it assumes a normal (return/newline exchange, etc) terminal.
  125. It does not do as much checking as the standard getty, but it's only looking
  126. at one character.
  127. X.PP
  128. X.I Newgetty
  129. assumes a fairly standard stdio, and uses one nonportable call.
  130. The routine
  131. X.IR finkey ()
  132. returns a single character from a standard I/O FILE; it uses
  133. X.IR rdchk ()
  134. to see if a character is available.
  135. BSD users can substitute FIONREAD; pure System\-5 users will have to change
  136. the terminal codes used anyways, so they can put the timeout codes in.
  137. V7 should just forget this.
  138. END_OF_FILE
  139. if test 1700 -ne `wc -c <'newgetty.man'`; then
  140.     echo shar: \"'newgetty.man'\" unpacked with wrong size!
  141. fi
  142. # end of 'newgetty.man'
  143. fi
  144. if test -f 'newgetty.c' -a "${1}" != "-c" ; then 
  145.   echo shar: Will not clobber existing file \"'newgetty.c'\"
  146. else
  147. echo shar: Extracting \"'newgetty.c'\" \(2660 characters\)
  148. sed "s/^X//" >'newgetty.c' <<'END_OF_FILE'
  149. X/* @(#)newgetty.c    2.2 4/18/88 17:55:29 ( 4/18/88 17:33:01 ) */
  150. X/* New getty program. If called with an argument other than 'b', it invokes
  151. X    the old getty program (assumed to be at /etc/lib/getty), otherwise
  152. X    it reads the default file (/etc/defaults/getty) for 'prompt=',
  153. X    displays the result, reads a character, loops if non-ascii, checks
  154. X    the default file for <char>=, executes that program if found, otherwise
  155. X    loops. */
  156. X
  157. X/* 0.4 Sys 3 mods: set echo, cooked */
  158. X/* Gave up on getting it to work with the sys3 structures. Will work fine
  159. for BSD systems, or Xenix systems. If you are pure USG, either link for
  160. version 7 mode (the kernel still has the version 7 stuff hidden inside
  161. for compatibility), or convert it yourself.
  162. X*/
  163. X
  164. X#include <ctype.h>
  165. X#include <stdio.h>
  166. X#include <sgtty.h>
  167. X
  168. X/* 0.3 Does not actually pass arg to next program */
  169. X/* Will not work at 2400 */
  170. X#define SPEED    (term.sg_ispeed >= B1200 ? "3":"5")
  171. X#define fnsleep(x)  (3)    /* Return time for sleep */
  172. X
  173. char *defread(), *mkstr();
  174. main(argc, argv)
  175. char *argv[];
  176. X{
  177. X    int c;
  178. X    char *x;
  179. X    struct sgttyb term;
  180. X    if (argc != 2 || strcmp (argv[1], "b") != 0)
  181. error:        execv ("/etc/lib/getty", argv);
  182. X    if (defopen("/etc/default/getty") != 0)
  183. X    {
  184. X        perror("new getty:");
  185. X        goto error;
  186. X    }
  187. X    ioctl (1, TIOCGETP, &term);  
  188. X    term.sg_ispeed = term.sg_ospeed = B9600;
  189. X    term.sg_flags |= CBREAK | ECHO | CRMOD;
  190. X    term.sg_flags &= ~RAW;
  191. X    ioctl (1, TIOCNXCL);
  192. X    for (;;)
  193. X    {
  194. X        ioctl (1, TIOCSETP, &term);
  195. X        puts ("\r");
  196. X        fputs(defread("prompt="), stdout);
  197. X        /* Flush input */
  198. X        while ((c=finkey(stdin)) != '\0' && c!= EOF)
  199. X            ;
  200. X        sleep(fnsleep(term.sg_ispeed));
  201. X        if (isalpha(c=finkey(stdin)) && (x=defread(mkstr(c))) !=NULL)
  202. X        {
  203. X            putchar('\n');
  204. X            term.sg_flags = term.sg_flags &~ CBREAK;
  205. X            if (isupper(c))
  206. X                term.sg_flags |= LCASE;
  207. X            ioctl (1, TIOCSETP, &term);
  208. X            /* No more alarm clock */
  209. X            execlp (x, x, NULL);
  210. X    /* Speed is no longer passed */
  211. X            perror (x);
  212. X            term.sg_flags |= CBREAK;
  213. X        }
  214. X        term.sg_ispeed = term.sg_ospeed = nextspeed (term.sg_ispeed);
  215. X                    /* Change speed & try again */
  216. X    }
  217. X}
  218. X
  219. char *mkstr(c)
  220. char c;
  221. X{
  222. X    static char chr[]="x=";
  223. X    chr[0]=c;
  224. X    return chr;
  225. X}
  226. X
  227. nextspeed(oldspeed)
  228. X{
  229. X    switch (oldspeed)
  230. X    {    case B300: return B9600;
  231. X        case B1200: return B300;
  232. X        case B2400: return B1200;
  233. X        case B9600: return B2400;
  234. X    }
  235. X}
  236. X
  237. X/* @(#)inkey.c    1.1 4/18/88 17:57:48 ( 10/2/86 18:51:54 ) */
  238. X# include <stdio.h>
  239. inkey(fd)
  240. int fd;
  241. X{
  242. X    char c;
  243. X    int temp;
  244. X    if (temp=rdchk(fd) > 0)
  245. X        if (read (fd, &c, 1) >0)
  246. X            return c;
  247. X        else return (char) -1;
  248. X    else return (temp == 0 ? 0 : -1);
  249. X}
  250. X
  251. finkey(fp)
  252. XFILE *fp;
  253. X{
  254. X    if ((fp->_cnt > 0) || rdchk(fileno(fp)) > 0)
  255. X        return getc (fp);
  256. X    if feof(fp)
  257. X        return EOF;
  258. X    return 0;
  259. X}
  260. END_OF_FILE
  261. if test 2660 -ne `wc -c <'newgetty.c'`; then
  262.     echo shar: \"'newgetty.c'\" unpacked with wrong size!
  263. fi
  264. # end of 'newgetty.c'
  265. fi
  266. echo shar: End of shell archive.
  267. exit 0
  268.